package com.czk.netty.netty.http;

import com.czk.netty.netty.http.tomcat.PathScanner;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/1/14 21:49
 */
public class HttpServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        // 扫描
        if (PathScanner.getMap().size()==0){
            PathScanner.scan("com.czk.netty.netty.http.tomcat");
        }

        // 加入处理器
        // 得到管道
        ChannelPipeline pipeline = socketChannel.pipeline();
        // 加入netty提供的处理器httpServerCodec codec
        // netty提供的处理http的编解码处理器
        pipeline.addLast("MyHttpServerCodec", new HttpServerCodec());
        // 增加自定义处理器
        pipeline.addLast("MyHttpServerHandler", new HttpServerHandler());
    }
}
